package com.black.service.controller;

import com.alibaba.fastjson2.JSONObject;
import com.black.protocol.Response;
import com.black.service.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/service/user")
public class UserController {

    final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/verify_code")
    public Response<?> verifyCode(HttpServletRequest request) {
        return userService.verifyCode(request);
    }

    @PostMapping("/email_code")
    public Response<?> emailCode(HttpServletRequest request, @RequestBody String paramStr) {
        JSONObject param = JSONObject.parseObject(paramStr);
        return userService.emailCode(request, param);
    }

    @PostMapping("/register")
    public Response<?> register(HttpServletRequest request, @RequestBody String paramStr) {
        JSONObject param = JSONObject.parseObject(paramStr);
        return userService.register(request, param);
    }

    @PostMapping("/login")
    public Response<?> login(HttpServletRequest request, @RequestBody String paramStr) {
        JSONObject param = JSONObject.parseObject(paramStr);
        return userService.login(request, param);
    }

    @DeleteMapping("/logout")
    public Response<?> logout(@RequestBody String paramStr) {
        JSONObject param = JSONObject.parseObject(paramStr);
        return userService.logout(param);
    }

    @PostMapping("/check_email")
    public Response<?> checkEmail(@RequestBody String paramStr) {
        JSONObject param = JSONObject.parseObject(paramStr);
        return userService.checkEmail(param);
    }

    @PostMapping("/forget")
    public Response<?> forget(HttpServletRequest request, @RequestBody String paramStr) {
        JSONObject param = JSONObject.parseObject(paramStr);
        return userService.forget(request, param);
    }

    @PostMapping("/unsubscribe")
    public Response<?> unsubscribe(HttpServletRequest request, @RequestBody String paramStr) {
        JSONObject param = JSONObject.parseObject(paramStr);
        return userService.unsubscribe(request, param);
    }

    @PostMapping("/update")
    public Response<?> update(HttpServletRequest request, @RequestBody String paramStr) {
        JSONObject param = JSONObject.parseObject(paramStr);
        return userService.update(request, param);
    }

    @PostMapping("donatePoints")
    public Response<?> donatePoints(HttpServletRequest request, @RequestBody String paramStr) {
        JSONObject param = JSONObject.parseObject(paramStr);
        return userService.donatePoints(request, param);
    }
}
